#include "stdafx.h"
#include "Egg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CEgg::CEgg(void):m_Bitmap(NULL)
{
	
}
CEgg::CEgg(int x,int offset_move,int m_iType):m_Bitmap(NULL)
{
	//trung loai 1
	if(m_iType == 1)
	{
		m_Bitmap = new CCBitmap(_EGG_T1);
		m_iScore = EGG_SCORE_T1;
	}
	if(m_iType == 2)//chat thai
	{
		m_Bitmap = new CCBitmap(_EGG_SHIT);
		m_iScore = EGG_SCORE_T2;
	}
	m_Cx = x;
	m_Cy = GM_TOP + ANIMAL_HEIGHT + 15;
	m_iEgg_Type = m_iType;
	m_iBlock = offset_move;
}

CEgg::~CEgg(void)
{
	//delete m_Bitmap;
}

void CEgg::Draw(CDC *pDC)
{	
	CDC dcMem;
	dcMem.CreateCompatibleDC (pDC);
	dcMem.SelectObject(&m_Bitmap->m_Bitmap);
	pDC->StretchBlt(m_Cx,m_Cy,EGG_WIDTH,EGG_HEIGHT,&dcMem,0,0,m_Bitmap->m_bmWidth,m_Bitmap->m_bmHeight,SRCCOPY);
	dcMem.DeleteDC();

	//CDC memDC;
	//memDC.CreateCompatibleDC(pDC);
	//memDC.SelectObject(&m_Bitmap->m_Bitmap);
	//// set transparent
 //   // create mask
 //   CDC* dcMask = new CDC();
 //   CBitmap* bmMask = new CBitmap();
 //   dcMask->CreateCompatibleDC(pDC);
 //   bmMask->CreateBitmap(EGG_WIDTH,EGG_HEIGHT,1,1,0 );
 //   dcMask->SelectObject(&bmMask);
	//dcMask->StretchBlt(m_Cx,m_Cy,EGG_WIDTH,EGG_HEIGHT,&memDC,0,0,m_Bitmap->m_bmWidth,m_Bitmap->m_bmHeight,SRCCOPY);
	//pDC->StretchBlt(m_Cx,m_Cy,EGG_WIDTH,EGG_HEIGHT,dcMask,0,0,m_Bitmap->m_bmWidth,m_Bitmap->m_bmHeight,SRCPAINT);
	//pDC->StretchBlt(m_Cx,m_Cy,EGG_WIDTH,EGG_HEIGHT,&memDC,0,0,m_Bitmap->m_bmWidth,m_Bitmap->m_bmHeight,SRCAND);

	//bmMask->DeleteObject();
	//dcMask->DeleteDC();
	//memDC.DeleteDC();
}

int CEgg::Egg_Proc(int basket_x)
{
	if(Egg_Move() == 1)// trung cham san
	{
		if(m_iEgg_Type == EGG_T1)
		{
			return -1; // Khong hung duoc trung thong thuong - 1 mang
		}
		return -2; // khong phai trung co ban // trung crit / shit
	}
	return Egg_Basket(basket_x);
}
int CEgg::Egg_Move()
{
	// roi cham dat
	if((m_Cy + m_iBlock)>=(GM_BOTTOM - EGG_HEIGHT - 5))
	{
		m_Cy = (GM_BOTTOM - EGG_HEIGHT - 5);
		return 1;// trung cham san
	}
	// dang roi - cao do moi cho trung
	m_Cy += m_iBlock;
	return 0;
}

int CEgg::Egg_Basket(int basket_x)
{
	if(m_Cx >basket_x & (m_Cx + EGG_WIDTH)< (basket_x + BASKET_WIDTH))
	{
		if((m_Cy + EGG_HEIGHT) > (BASKET_Y+ BASKET_HEIGHT/3) & (m_Cy + EGG_HEIGHT)< BASKET_EGG)
		{
			if(m_iEgg_Type == EGG_SHIT)
			{
				return -1; // hung phai shit
			}
			else
			{
				return m_iScore; // hung trung co diem
			}
		}
	}
	return 0; // khong xu ly gi het
}